 /* =====================================================================================
 *       Filename:  packets_1017.cc
 *
 *    Description:  how to place the packets so that use the minimal box
 *
 *        Version:  1.0
 *        
 *        Created:  09/17/2012 01:23:29 AM
 * =====================================================================================
 */
#include	<stdio.h>
#include	<algorithm>

int main(int argc, char *argv[])
{
   int sizeCnt[8];
   while (scanf("%d%d%d%d%d%d", &sizeCnt[1],  &sizeCnt[2], 
            &sizeCnt[3], &sizeCnt[4], &sizeCnt[5], &sizeCnt[6]) == 6)
   {
       int sum = sizeCnt[6] + sizeCnt[1] + sizeCnt[2] 
           + sizeCnt[3] + sizeCnt[4] + sizeCnt[5];
       if (sum == 0) break;

       int res = sizeCnt[6] + sizeCnt[5] + sizeCnt[4];
       sizeCnt[1] -= sizeCnt[5] * 11;

       int r2bak = sizeCnt[2];
       sizeCnt[2] -= sizeCnt[4] * 5;
       if (sizeCnt[2] < 0) {
           sizeCnt[1] -= (20 * sizeCnt[4] - 4 * r2bak);
       }
       
       if (sizeCnt[3] > 0) {
           res += (sizeCnt[3] / 4 + 1);
           int threeRemain = sizeCnt[3] % 4;
           if (threeRemain != 0) {
               int remainSize = 36 - threeRemain * 9;
               int c2 = remainSize / 4 - 1; // through look
               int c1 = remainSize - c2 * 4;
               sizeCnt[2] -= c2;
               sizeCnt[1] -= c1;
           } else 
               --res;
       }

       if (sizeCnt[2] > 0) {
           res += (sizeCnt[2] / 9 + 1);
           int r2 = sizeCnt[2] % 9;
           if (r2 != 0) {
               sizeCnt[1] -= (36 - 4 * r2);
           } else 
               --res;
       }
       if (sizeCnt[1] > 0) {
           res += (sizeCnt[1] / 36 + 1);
           if (sizeCnt[1] % 36 == 0)
               --res;
       }
       printf ( "%d\n", res);
   }
   return 0;
}
